//连接数据库 在app.js中调用
var mongoose = require('mongoose')
 const hostname = 'localhost';
 const port = 27017;
 const dbname = 'wh2008'
 const  db_conn_str = `mongodb://${hostname}:${port}/${dbname}`
mongoose.connect(db_conn_str,{
    useNewUrlParser:true,
    useUnifiedTopology:true
},function(err){
    if(err){
        console.log('数据库连接失败');
    }else{
        console.log('数据库连接成功');
    }
})
const connection = mongoose.connection

connection.on('connected',function(){
    console.log("数据库已经正确链接---connected");
})

connection.on("error",function(err){
    console.log("数据库无法正常链接---error")
})

connection.on("disconnected",()=>{
    console.log("数据库已经断开链接---disconnected")
})

module.exports = connection;